package gov.ccswj.modules.bdbusiness.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gov.ccswj.modules.bdbusiness.entity.AaProductEntity;
import gov.ccswj.modules.bdbusiness.entity.AaWorldCompanyEntity;
import gov.ccswj.modules.bdbusiness.entity.BAExhibitioninfoEntity;
import gov.ccswj.modules.bdbusiness.service.AaProductService;
import gov.ccswj.modules.ccbusiness.entity.CRegisterinfoEntity;
import gov.ccswj.common.utils.PageUtils;
import gov.ccswj.common.utils.Query;
import gov.ccswj.common.utils.R;
/**
 * @author KY.Cheng
 * @email ********@gmail.com
 * @date 2017-12-29 10:29:13
 */
@RestController
@RequestMapping("/bdbusiness/aaproduct")
public class AaProductController {
	@Autowired
	private AaProductService aaProductService;
	
	/**
	 * 产品列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<AaProductEntity> aaProductList = aaProductService.queryList(query);
		int total = aaProductService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(aaProductList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}

	/**
	 * 内贸信息
	 */
	@RequestMapping("/domestictradedetails/{id}")
	public R domestictradedetails(@PathVariable("id") Integer id){
		AaProductEntity aaProduct = aaProductService.queryObject(id);
		
		Map<String, Object> params = new HashMap<>();
		params.put("type", "0");
		params.put("keyword", aaProduct.getKeyword());
		List<BAExhibitioninfoEntity> list1=aaProductService.queryListBAExhibitioninfo(params);
		List<CRegisterinfoEntity> list2=aaProductService.queryListCRegisterinfo(params);
		return R.ok().put("list1", list1).put("list2", list2);
	}
	/**
	 * 外贸信息
	 */
	@RequestMapping("/foreigntradedetails/{id}")
	public R foreigntradedetails(@PathVariable("id") Integer id){
		AaProductEntity aaProduct = aaProductService.queryObject(id);

		Map<String, Object> params = new HashMap<>();
		params.put("type", "1");
		params.put("keyword", aaProduct.getKeyword());
		List<BAExhibitioninfoEntity> list1=aaProductService.queryListBAExhibitioninfo(params);
		List<AaWorldCompanyEntity> list2=aaProductService.queryListAaWorldCompany(params);
		return R.ok().put("list1", list1).put("list2", list2);
	}
}
